<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 * Description of GContacto
 *
 * @author Luis Alberto
 */
include './libs/adodb/adodb.inc.php';
include './configuracion.php';
include 'Contacto.php';
class GContacto
{
    private $db;
    private $contacto=null;
    public function __construct()
    {
        $this->contacto = new Contacto();
    }
    public function Nuevo()
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
	$cns = "select max(con_cod) as codigo from contacto";
	$rs = $db->Execute($cns);
        if($rs)
        {
            $dato = $rs->fetchRow();
            return $dato;
        }
        return null;
    }
    public function Guardar($nomb,$apell,$dir,$fenac,$cel,$tel,$email,$recemail,$desc,$img,$twt,$fb,$carg,$org,$emp)
    {        
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);     
        $cns = "insert into contacto (con_nombre, con_apellidos, con_direccion, con_fecha_nac, con_celular, ";
        $cns .= "con_telefono, con_email , con_recibe_email, con_descripcion, con_imagen, con_twitter, con_facebook, con_cargo, ori_cod, emp_cod)";
        $cns .= " values ('$nomb','$apell','$dir','$fenac','$cel','$tel','$email',$recemail,'$desc','$img','$twt','$fb','$carg',$org,$emp)";
        $rs = $db->Execute($cns);
        return $rs;
    }
    public function Modificar($con_cod,$nomb,$apell,$dir,$fenac,$cel,$tel,$email,$recemail,$desc,$img,$twt,$fb,$carg,$org,$emp)
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
	$cns = "update contacto";
        $cns .= " set con_nombre = '$nomb', con_apellidos='$apell', con_direccion='$dir', con_fecha_nac='$fenac', con_celular='$cel', ";
        $cns .= "con_telefono='$tel', con_email='$email', con_recibe_email=$recemail, con_descripcion='$desc', ";
        $cns .= "con_imagen='$img', con_twitter='$twt', con_facebook='$fb', con_cargo='$carg', ori_cod=$org, emp_cod=$emp";
        $cns .= " where (con_cod = $con_cod)";
        return $rs = $db->Execute($cns);
    }
    public function Eliminar($cod)
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
	$cns = "delete from contacto where con_cod=$cod";
        return $rs = $db->Execute($cns);
    }
    public function Obtener($cod)
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
	$cns = "select * from contacto where con_cod = $cod";
	$rs = $db->Execute($cns);
        if($rs)
        {
            $dato = $rs->fetchRow();
            $this->contacto->setcon_cod($dato['con_cod']);
            $this->contacto->setcon_nombre($dato['con_nombre']);
            $this->contacto->setcon_apellidos($dato['con_apellidos']);
            $this->contacto->setcon_direccion($dato['con_direccion']);
            $this->contacto->setcon_fecha_nac($dato['con_fecha_nac']);
            $this->contacto->setcon_celular($dato['con_celular']);
            $this->contacto->setcon_telefono($dato['con_telefono']);
            $this->contacto->setcon_email($dato['con_email']);
            $this->contacto->setcon_recibe_email($dato['con_recibe_email']);
            $this->contacto->setcon_descripcion($dato['con_descripcion']);
            $this->contacto->setcon_imagen($dato['con_imagen']);
            $this->contacto->setcon_twitter($dato['con_twitter']);
            $this->contacto->setcon_facebook($dato['con_facebook']);
            $this->contacto->setcon_cargo($dato['con_cargo']);
            $this->contacto->setcon_ori_cod($dato['ori_cod']);
            $this->contacto->setcon_emp_cod($dato['emp_cod']);
            return $this->contacto;
        }
        return null;
    }
    public function Obtenerorigencontactos()
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
        $cns = "select * from origencontacto";
        $rs = $db->Execute($cns);
        $l = $rs->GetRows();
        return $l;
    }
    public function Obtenerempresas()
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
        $cns = "select * from empresa";
        $rs = $db->Execute($cns);
        $l = $rs->GetRows();
        return $l;
    }
    public function Buscar($buscar, $campo)
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
        $cns = "select * from contacto where $campo like '%$buscar%'";
        $rs = $db->Execute($cns);
        $l = $rs->GetRows();
        return $l;
    }
    public function Seleccionar()
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
        $cns = "select * from contacto";
        $rs = $db->Execute($cns);
        $l = $rs->GetRows();
        return $l;
    }
    public function SeleccionarLetra($letra)
    {
        $db = ADONewConnection(DRIVER);
        $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
        $cns = "select * from contacto where con_nombre like '$letra%'";
        $rs = $db->Execute($cns);
        $l = $rs->GetRows();
        return $l;
    }
}
?>
